// Multi-chain configuration for admin dashboard

export type ChainType = 'mainnet' | 'testnet';

export interface ChainConfig {
  id: ChainType;
  name: string;
  displayName: string;
  apiUrl: string;
  chainId: number;
  rpcUrl: string;
  explorerUrl: string;
  isTestnet: boolean;
  contracts: {
    token: string;
    vesting: string;
    nft: string;
    mining: string;
    multisig: string;
  };
}

export const CHAIN_CONFIGS: Record<ChainType, ChainConfig> = {
  mainnet: {
    id: 'mainnet',
    name: 'BSC Mainnet',
    displayName: 'Mainnet',
    apiUrl: process.env.NEXT_PUBLIC_MAINNET_API_URL || 
           (process.env.NODE_ENV === 'development' ? 'http://localhost:9000' : 'https://admin.detvs.dev'),
    chainId: 56,
    rpcUrl: 'https://bsc-dataseed1.binance.org',
    explorerUrl: 'https://bscscan.com',
    isTestnet: false,
    contracts: {
      token: '0xC39B3d7fc61287047A9795E07961AD4562689cEd',
      vesting: '0x5FBda2E9440a170c17a03034732122817a45218b',
      nft: '0x552201516ec3612B04a275C878F6E7DA5E4af9Bc',
      mining: '0xD94bF46aF1Bacc4721C1B321785E24c61DBf58D4',
      multisig: '0x34F4df02b552B9f98e94774bDBC03f04b0F52d6A',
    },
  },
  testnet: {
    id: 'testnet',
    name: 'BSC Testnet',
    displayName: 'Testnet',
    apiUrl: process.env.NEXT_PUBLIC_TESTNET_API_URL || 
           (process.env.NODE_ENV === 'development' ? 'http://localhost:9001' : 'https://api-test.detv.media'),
    chainId: 97,
    rpcUrl: 'https://data-seed-prebsc-1-s1.binance.org:8545',
    explorerUrl: 'https://testnet.bscscan.com',
    isTestnet: true,
    contracts: {
      token: '0x1346bf38410FE3Be44e7aD4F62Aa619dc65c81FF',
      vesting: '0xFaE7Ca68F58b99Bc6a1435A2F974bd2cE1eDB7FB',
      nft: '0xaeaf7519CDA38CA1D0c5de6Fe8DF479304388414',
      mining: '0xbc453125776F5caEd852657485765EE41e51994E',
      multisig: '0xD8bDB263a54B44d4CBabe45E859ae7582A2FfB1B',
    },
  },
};

export const DEFAULT_CHAIN: ChainType = 'mainnet';

// Helper functions
export const getChainConfig = (chainId: ChainType): ChainConfig => {
  return CHAIN_CONFIGS[chainId];
};

export const getAllChains = (): ChainConfig[] => {
  return Object.values(CHAIN_CONFIGS);
};

export const isValidChain = (chainId: string): chainId is ChainType => {
  return chainId === 'mainnet' || chainId === 'testnet';
};